﻿using Vigenere_cipher.Models;

namespace Vigenere_cipher
{
    internal class Program
    {
        /// <summary>
        /// 维吉尼亚密码的加密和解密
        /// </summary>
        /// <param name="args"></param>      

        static void Main(string[] args)
        {
            Console.WriteLine("请输入你要进行的操作：\n1、维吉尼亚密码加密\n2、维吉尼亚密码解密");
            int choice = Convert.ToInt32(Console.ReadLine());
            if (choice==1)
            {
                Console.Clear();
                TextInPassword();
                Console.ReadKey();
            }
            if (choice==2)
            {
                Console.Clear();
                PasswordInText();
                Console.ReadKey();
            }
        }
        /// <summary>
        /// 加密
        /// </summary>
        private static void TextInPassword()
        {
            //输入明文
            Console.Write("请输入要加密的字符串:");
            string input = Console.ReadLine();
            //输入key
            Console.Write("请输入密钥:");
            string key = Console.ReadLine();
            //加密
            MyCoder myEncoder = new MyCoder();
            myEncoder.PlainText=input;
            myEncoder.Key=key;
            myEncoder.Ecode();
            //输出密文
            Console.WriteLine($"加密后的密文：{myEncoder.CipherText}");
        }
        /// <summary>
        /// 解密
        /// </summary>
        private static void PasswordInText()
        {
            //输入密文
            Console.Write("请输入要解密的字符串:");
            string input = Console.ReadLine();
            //输入key
            Console.Write("请输入密钥:");
            string key = Console.ReadLine();
            //解密
            MyCoder myDecoder = new MyCoder();
            myDecoder.CipherText=input;
            myDecoder.Key=key;
            myDecoder.Dcode();
            //输出明文
            Console.WriteLine($"解密后的明文：{myDecoder.PlainText}");
        }
    }
}
